﻿
@{
    ViewBag.Title = "Index";
}

<script src="~/Scripts/yui-min.js"></script>
<h2>Index</h2>
<div id="demo" class="yui3-skin-sam">
    <p>Click the <em>Get Messages</em> button to send the request to the server; the response will be displayed below the button.</p>
    <p><button>Get Messages</button></p>
    <div id="demo-messages"></div>
</div>
<script>
    // Create business logic in a YUI sandbox using the 'io' and 'json' modules
    YUI().use("node", "io", "dump", "json-parse", "datatable", function (Y) {


        // Create the io callback/configuration
        var callback = {

            timeout: 30000,

            on: {
                success: function (x, o) {
                    Y.log("RAW JSON DATA: " + o.responseText);

                    var messages = [],
                        html = '', i, l;

                    // Process the JSON data returned from the server
                    try {
                        messages = Y.JSON.parse(o.responseText);
                    }
                    catch (e) {
                        alert("JSON Parse failed!");
                        return;
                    }

                    Y.log("PARSED DATA: " + Y.Lang.dump(messages));

                    var table = new Y.DataTable({
                        columns: ["id", "Nombre", "Uri"],
                        data: messages,

                        // Optionally configure your table with a caption
                        caption: "My first DataTable!",

                        // and/or a summary (table attribute)
                        summary: "Example DataTable showing basic instantiation configuration"
                    });

                    table.render("#demo-messages");
                },

                failure: function (x, o) {
                    alert("Async call failed!");
                }

            }
        };

        // Attach a click event listener to the button #demo_btn to send the request
        Y.one('#demo button').on('click', function (e) {
            // Make the call to the server for JSON data
            Y.io("/api/resources", callback);
        });

    });
</script>